package triFileSystem;

import transaction.*;

public class FileDir implements Inode {

	private int lastPageId;
	
	private Object accessLock = new Object();
	
	public FileDir(int lastPageId) {
		this.lastPageId = lastPageId;
	}
	
	@Override
	public FileDir copy(Transaction tx) {
		synchronized (accessLock) {
			return new FileDir(lastPageId);
		}
	}
	
	@Override
	public int getIthPageId(int ith) {
		synchronized (accessLock) {
			if (ith <= lastPageId)
				return ith;
			return -1;
		}
	}

	@Override
	public int getLastPageId() {
		synchronized (accessLock) {
			return lastPageId;
		}
	}

	@Override
	public void allocNewPageId(int pageId, Transaction tx) {
		synchronized (accessLock) {
			lastPageId = pageId;
		}
	}

}
